package be.scond.cartpool;

import java.io.IOException;
import javax.servlet.http.*;
import be.scond.cartpool.API.ShoppingListApi;
import be.scond.cartpool.exceptions.OrderDoesNotExistException;

public class DeleteOrderServlet extends HttpServlet {
	
	static final long serialVersionUID = 1;
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
	}
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		resp.setCharacterEncoding("UTF-8");
		resp.setContentType("text/xml");		
		
		String respons = "<data>";	

		String keyString = req.getParameter("key");
		try {
			ShoppingListApi.deleteOrder(keyString);
			respons += "<succes>Deleted order.</succes>";			
		} catch (OrderDoesNotExistException e) {
			respons += "<error>Order was not found</error>";				
		}
			
		respons += "</data>";

		resp.getWriter().print(respons);
	}
}